<template>
	<view>
		<l-file ref="lFile" @up-success="onSuccess"></l-file>
		<view class="list-box">
			<view v-for="(att,index) in atts" :key="index">
				{{att.FileName}}
				<button class="fr" @click="onOpenDoc(att)">预览</button>
				<button class="fr" @click="onDown(att)">下载</button>
			</view>
		</view>
	</view>
</template>

<script>
	import {Url,bpmUrl} from "@/common/config.js"
	import {ajax,getUserInfo} from '@/common/common.js'
	import lFile from '@/components/l-file/l-file.vue'
	export default {
		data() {
			return {
				atts: []
			};
		},
		onLoad() {
			this.initBussinessField()
		},
		components:{lFile},
		methods:{
			onOpenDoc(item) {
				let url = item.url;
				/* 下载返回临时路径（退出应用失效） */
				this.$refs.lFile.download(url)
				.then(path=>{
					/* 预览 */
					this.$refs.lFile.open(path);
				});
			},
			
			/* 保存 */
			onDown(item) {
				let url = item.url;
				this.$refs.lFile.download(url,'local')
				.then(path=>{
					this.localPath = path;
					console.log(this.localPath)
				}); 
			},
			onSuccess(res) {
				console.log('上传成功回调',JSON.stringify(res));
				uni.showToast({
					title: JSON.stringify(res),
					icon: 'none'
				})
			},
			//填充业务字段
			initBussinessField(){
				let user = getUserInfo()
				let params = {
					paramasMap : {
						docUnid:"7333191e0c08604b02083180326a324a042f",
					},
					headersMap: {
						sysid: "bpm",
						syspwd: "pass",
						userid: user.bpmUid
					},
					url: bpmUrl + "/rest/attachment/list"
				};
				ajax({
					url: '/bpm/get',
					method: 'POST',
					data: params,
					success: res => {
						console.log('att',res)
						this.atts = res.data.data.map(item => {
							item.url = bpmUrl + '/' + item.FilePath
							return item
						})
					}
				})
			}
		}
	}
</script>

<style lang="scss">

</style>
